/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-20
 * Time: 16:22
 */
class Solution8 {
    public int maxProfit(int[] prices) {
        int n = prices.length,ret = 0;
        for(int i = 0,premin = Integer.MAX_VALUE; i < n; i++) {
            //先更新结果
            ret = Math.max(ret,prices[i]-premin);
            //更新min
            premin = Math.min(premin,prices[i]);
        }
        return ret;
    }
}
